
<template>
  <div class="setting-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <!-- 左侧 -->
          <el-tab-pane label="货架管理">
            <span>所属仓库：</span>
            <el-select v-model="depValue" @change="selectDep" placeholder="请选择仓库" >
              <el-option
                v-for="(item,index) in depList"
                :key="item.id"
                :label="item.name"
                :value="index">
              </el-option>
            </el-select>
            <span  class="ml-10">所属分区：</span>
            <el-select v-model="parValue"  placeholder="请选择分区" >
              <el-option
                v-for="(item) in parList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
            <!-- <el-button type="primary" size="medium">
              请选择分区<i class="el-icon-arrow-down el-icon--right" />
            </el-button> -->
            <el-button
            class="ml-10"
              type="primary"
              size="medium"
              icon="el-icon-search"
              @click="search"
            >查询</el-button>
            <el-button type="primary" size="medium" @click="showDialog=true">
              <i class="el-icon-plus" />新建货架
            </el-button>
            <!-- 表格 -->
            <el-table :data="list">
               <el-table-column label="序号" prop="name">
                <template #default="{ row }">
                  {{ row.id }}
                </template>
              </el-table-column>
              <!-- <el-table-column prop="serial" label="序号" width="50" /> -->
               <el-table-column prop="name" label="所属仓库" />
               <el-table-column prop="name" label="所属分区" />
              <el-table-column prop="sort" label="货架号"/>
              <el-table-column prop="statename" label="状态" />
              <el-table-column prop="storagename" label="情况" />
              <el-table-column prop="num" label="总库位数" />
              <el-table-column prop="size" label="尺寸" />
              <el-table-column prop="shelvesRow" label="排数" />
              <el-table-column prop="remarks" label="货架备注" />
              <el-table-column prop="locationOneMax" label="一号库位最大包裹数" width="150"/>
              <el-table-column prop="locationTwoMax" label="二号库位最大包裹数" width="150"/>
              <el-table-column prop="locationThreeMax" label="三号库位最大包裹数" width="150"/>
              <el-table-column prop="locationFourMax" label="四号库位最大包裹数" width="150"/>
              <el-table-column prop="locationFiveMax" label="五号库位最大包裹数" width="150"/>
              <el-table-column prop="locationSixMax" label="六号库位最大包裹数" width="150"/>
              <el-table-column prop="locationSevenMax" label="七号库位最大包裹数" width="150"/>
              <el-table-column prop="locationEightMax" label="八号库位最大包裹数" width="150"/>
              <el-table-column prop="locationNineMax" label="九号库位最大包裹数" width="150"/>
              <el-table-column prop="locationZeroMax" label="十号库位最大包裹数" width="150"/>
              <el-table-column prop="text"  fixed="right" label="操作" width="200">
                <template  slot-scope="scope">
                  <el-button size="small" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
                  <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                </template>
                
              </el-table-column>
            </el-table>
          </el-tab-pane>

        </el-tabs>
      </el-card>

    </div>
    <!-- 分页 -->
    <div align="center">
      <el-pagination
        :current-page.sync="currentPage"
        layout="prev, pager, next, jumper"
        :total="list.length"
      />
    </div>
     <!-- 新增、修改弹窗 -->
    <el-dialog  :visible="showDialog" @close="closeDialog">
      <el-form label-width="150px">
        <el-form-item prop="depositoryid" label="所属仓库" v-if="!formData.id">
          <el-select v-model="formData.depositoryid" @change="selectDep2" placeholder="请选择">
            <el-option
              v-for="item in depList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="fpartitionId" label="所属分区">
          <el-select v-model="formData.fpartitionId" placeholder="请选择">
            <el-option
              v-for="item in selectParList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="货架号" prop="name">
          <el-input v-model="formData.name" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="几号货架" prop="sort">
          <el-input v-model="formData.sort" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-switch
            v-model="formData.state"
            :active-text="formData.state?'有效':'无效'"
            active-color="#13ce66"
            inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
        <el-form-item label="是否已满" prop="storage">
          <el-switch
            v-model="formData.storage"
            :active-text="formData.storage?'未满':'已满'"
            active-color="#13ce66"
            inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
        <el-form-item label="尺寸" prop="size">
          <el-input type="number" v-model="formData.size" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="总排数" prop="name">
          <el-input type="number" v-model="formData.shelvesRow" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="总库位" prop="name">
          <el-input type="number" v-model="formData.num" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="备注" prop="name">
          <el-input v-model="formData.remarks" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="一号库位最大包裹" prop="locationOneMax">
          <el-input v-model="formData.locationOneMax" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="二号库位最大包裹" prop="locationTwoMax">
          <el-input v-model="formData.locationTwoMax" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="三号库位最大包裹" prop="locationThreeMax">
          <el-input v-model="formData.locationThreeMax" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="四号库位最大包裹" prop="locationFourMax">
          <el-input v-model="formData.locationFourMax" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="五号库位最大包裹" prop="locationFiveMax">
          <el-input v-model="formData.locationFiveMax" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="六号库位最大包裹" prop="locationSixMax">
          <el-input v-model="formData.locationSixMax" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="七号库位最大包裹" prop="locationSevenMax">
          <el-input v-model="formData.locationSevenMax" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="八号库位最大包裹" prop="locationEightMax">
          <el-input v-model="formData.locationEightMax" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="九号库位最大包裹" prop="locationNineMax">
          <el-input v-model="formData.locationNineMax" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="十号库位最大包裹" prop="locationZeroMax" >
          <el-input v-model="formData.locationZeroMax" placeholder="请输入" />
        </el-form-item>
      </el-form>

      <template #footer>
        <div style="text-align: right;">
          <el-button @click="showDialog=false">取消</el-button>
          <el-button type="primary" @click="editSubmit">确认</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog
        title="提示"
        :visible.sync="deleteVisible"
        width="30%"
      >
        <span>确定删除吗？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="deleteVisible = false">取 消</el-button>
          <el-button type="primary" @click="deleteComfirm">确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { selectAllDep,fpartitionByDepId,selectShelvesByFid ,updateShelves,insertShelves,deleteShelves} from '@/api/depository'

export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  data() {
    return {
      depValue:'',//所选仓库
      depList:[], //仓库列表
      parList:[],//分区列表
      parValue:'',//所选分区
      currentPage: 1,
      list: [
      ],
      showDialog:false,
      deleteVisible:false,
      formData:{

      },
      deleteId:null,
      selectParList:[]
    }
  },
  mounted(){
    this.selectAllDep()
  },
  methods: {
    async selectAllDep(){
      this.depList = await selectAllDep()
    },
    async selectDep(){
      // this.getParList(this.depList[e].id)
      const parList = await fpartitionByDepId({
        depId:this.depList[this.depValue].id
      })
      this.parList = parList
    },
    async parChange(){
       const parList = await selectShelvesByFid({
        fpartitionId:this.depList[this.depValue].id
      })
      this.parList = parList
    },
    async search(){
      const res = await selectShelvesByFid({
        fpartitionId: this.parValue
      })
      if(res){
        res.map((item)=>{
          item.statename = item.state?'有效':'无效'
          item.storagename = item.storage?'未满':'已满'
          return item
        })
        this.list = res
      }
      
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
    },
    closeDialog(){
      this.showDialog = false
    },
    async editSubmit(){
      if(this.formData.id){
        await updateShelves(this.formData)
      }else{
        console.log(this.formData)
        await insertShelves(this.formData)
      }
      this.showDialog=false;
      this.search()
    },
    handleDelete(row){
      this.deleteId=row.id
      this.deleteVisible=true
    },
    async deleteComfirm(){
      await deleteShelves({
        id:this.deleteId
      })
      this.$message.success('操作成功')
      this.search()
      this.deleteVisible = false
    },
    handleEdit(row){
      this.formData = row
      this.showDialog = true
    },
    async selectDep2(){
      const res = this.selectParList = await fpartitionByDepId({
        depId:this.formData.depositoryid
      })
      if(res.length){
        this.formData.fpartitionId = this.selectParList[0].id
      }
      
    }
  },
 

}
</script>

<style lang="scss" scoped>
  .xinzeng{
    width: 70px;
    height:40px;
    float:right;
    margin-top: -55px;
    margin-left: 210px
  }
  .el-dropdown {
    vertical-align: top;
  }
  .el-dropdown + .el-dropdown {
    margin-left: 15px;
  }
  .el-icon-arrow-down {
    font-size: 10px;
  }
  .fenqu{
        width: 180px;
        height:40px;
        float: right;
        margin-top: -70px;
        margin-right: 550px;
  }
  .del{
    width: 50px;

  }
</style>

